//客户端
import java.net.*;
import java.util.*;
public class Client_Main {
    public static void main(String[] args) {
        /*Connection con=null;
        Statement sql;
        ResultSet rs;
        con =GetDBConnection.connectDB("students","root","111111");
        if (con==null)return;*/
        Scanner scanner=new Scanner(System.in);
        Thread readData;
        ReceiveLetterForServer receiver=new ReceiveLetterForServer();
        try{
            readData =new Thread(receiver);
            readData.start();
            byte [] buffer=new byte[1];
            InetAddress address=InetAddress.getByName("127.0.0.1");
            DatagramPacket dataPack=new DatagramPacket(buffer,buffer.length,address,666);
            DatagramSocket postman=new DatagramSocket();
            System.out.print("请输入给服务器发送到消息：");
            while(scanner.hasNext()){
                String mess=scanner.nextLine();
                buffer =mess.getBytes();
                /*String jilu="(mess,null)";
                String sqlStr="insert into mess values"+jilu;*/
                if(mess.length()==0)
                    System.exit(0);
                buffer =mess.getBytes();
                dataPack.setData(buffer);
                postman.send(dataPack);
                System.out.print("继续输入发给服务器的消息:");
            }
        }
        catch(Exception e){
            System.out.println("服务器已断开"+e);
        }
        /*try{
            sql=con.createStatement();
            int ok=sql.executeUpdate(sqlStr);
            rs=sql.executeQuery("select * from client_学号");
            while(rs.next()){
                String mess=rs.getString(1);
                String time=rs.getString(2);
                System.out.print(mess);
                System.out.print(time);
            }
            con.close();    
        }
        catch(SQLException e){
            System.out.println(e);
        }*/
    }

}